package com.pethome.pet.controller;

import com.pethome.common.annotation.Log;
import com.pethome.common.core.controller.BaseController;
import com.pethome.common.core.domain.AjaxResult;
import com.pethome.common.core.page.TableDataInfo;
import com.pethome.common.enums.BusinessType;
import com.pethome.common.utils.poi.ExcelUtil;
import com.pethome.pet.domain.PetKind;
import com.pethome.pet.service.IPetKindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 宠物品种Controller
 * 
 * @author hjc
 * @date 2024-08-26
 */
@RestController
@RequestMapping("/pet/kind")
public class PetKindController extends BaseController
{
    @Autowired
    private IPetKindService petKindService;

    @GetMapping("/getKindList")
    public TableDataInfo getKindList()
    {
        List<PetKind> list = petKindService.getKindList();
        return getDataTable(list);
    }


    //==========================================================================

    /**
     * 查询宠物品种列表
     */
    @PreAuthorize("@ss.hasPermi('pet:kind:list')")
    @GetMapping("/list")
    public TableDataInfo list(PetKind petKind)
    {
        startPage();
        List<PetKind> list = petKindService.selectPetKindList(petKind);
        return getDataTable(list);
    }

    /**
     * 导出宠物品种列表
     */
    @PreAuthorize("@ss.hasPermi('pet:kind:export')")
    @Log(title = "宠物品种", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PetKind petKind)
    {
        List<PetKind> list = petKindService.selectPetKindList(petKind);
        ExcelUtil<PetKind> util = new ExcelUtil<PetKind>(PetKind.class);
        util.exportExcel(response, list, "宠物品种数据");
    }

    /**
     * 获取宠物品种详细信息
     */
    @PreAuthorize("@ss.hasPermi('pet:kind:query')")
    @GetMapping(value = "/{petKindId}")
    public AjaxResult getInfo(@PathVariable("petKindId") Long petKindId)
    {
        return success(petKindService.selectPetKindByPetKindId(petKindId));
    }

    /**
     * 新增宠物品种
     */
    @PreAuthorize("@ss.hasPermi('pet:kind:add')")
    @Log(title = "宠物品种", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PetKind petKind)
    {
        return toAjax(petKindService.insertPetKind(petKind));
    }

    /**
     * 修改宠物品种
     */
    @PreAuthorize("@ss.hasPermi('pet:kind:edit')")
    @Log(title = "宠物品种", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetKind petKind)
    {
        return toAjax(petKindService.updatePetKind(petKind));
    }

    /**
     * 删除宠物品种
     */
    @PreAuthorize("@ss.hasPermi('pet:kind:remove')")
    @Log(title = "宠物品种", businessType = BusinessType.DELETE)
	@DeleteMapping("/{petKindIds}")
    public AjaxResult remove(@PathVariable Long[] petKindIds)
    {
        return toAjax(petKindService.deletePetKindByPetKindIds(petKindIds));
    }
}
